<template>
  <div id="PortalPage">
    <!-- 用户信息头部区域 -->
    <div class="user-header">
      <div class="user-info">
        <div class="user-avatar">
          <el-icon size="24"><User /></el-icon>
        </div>
        <span class="user-name">{{ userInfo.name || "用户" }}</span>
      </div>
      <div class="workspace-entry">
        <el-button type="primary" @click="goToWorkspace">
          <el-icon><Monitor /></el-icon>
          工作台
        </el-button>
      </div>

      <!-- 退出登录按钮 -->
      <el-icon
        title="退出登录"
        class="logout-icon"
        @click="logout"
        style="font-size: 2.2rem; cursor: pointer"
        ><SwitchButton
      /></el-icon>
    </div>

    <!-- 学校Banner区域 -->
    <div class="school-banner">
      <div class="banner-background">
        <img
          src="@/assets/images/banner.jpg"
          alt="学校banner"
          class="banner-image"
        />
        <div class="banner-overlay"></div>
        <div class="banner-pattern"></div>
      </div>
      <div class="banner-content">
        <div class="banner-left">
          <div class="school-info-container">
            <div class="school-logo"></div>
            <div class="school-info">
              <h1 class="school-name">启迪智慧</h1>
              <p class="school-desc">实验室管理系统</p>
            </div>
          </div>
          <div class="banner-decoration">
            <div class="decoration-circle circle-1"></div>
            <div class="decoration-circle circle-2"></div>
            <div class="decoration-circle circle-3"></div>
          </div>
        </div>
      </div>

      <!-- 顶部统计卡片 -->
      <div class="stats-grid">
        <div class="stat-card user-stats">
          <div class="stat-icon">
            <el-icon size="32"><User /></el-icon>
          </div>
          <div class="stat-content">
            <h3>用户总数</h3>
            <div class="stat-number">
              {{ overviewData?.totalUserCount || "--" }}
            </div>
            <p class="stat-desc">系统注册用户</p>
          </div>
        </div>

        <div class="stat-card equipment-stats">
          <div class="stat-icon">
            <el-icon size="32"><Monitor /></el-icon>
          </div>
          <div class="stat-content">
            <h3>设备总数</h3>
            <div class="stat-number">
              {{ overviewData?.totalDeviceCount || "--" }}
            </div>
            <p class="stat-desc">设备资产总量</p>
          </div>
        </div>

        <div class="stat-card booking-stats">
          <div class="stat-icon">
            <el-icon size="32"><Calendar /></el-icon>
          </div>
          <div class="stat-content">
            <h3>预约中</h3>
            <div class="stat-number">
              {{ overviewData?.total_reserved_count || "--" }}
            </div>
            <p class="stat-desc">预约中设备数量</p>
          </div>
        </div>
        <div class="stat-card booking-stats">
          <div class="stat-icon">
            <el-icon size="32"><Calendar /></el-icon>
          </div>
          <div class="stat-content">
            <h3>使用中</h3>
            <div class="stat-number">
              {{ overviewData?.total_in_use_count || "--" }}
            </div>
            <p class="stat-desc">使用中设备数量</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 图表区域 -->
    <div class="charts-section">
      <div class="chart-row">
        <!-- 设备类型分布 -->
        <div class="chart-card">
          <div class="card-header">
            <h3>设备类型分布</h3>
          </div>
          <div class="chart-content">
            <div class="pie-chart-container">
              <div ref="pieChartRef" class="pie-chart"></div>
              <div class="pie-chart-center">
                <div class="total-count">
                  {{ overviewData?.totalDeviceCount || 0 }}
                </div>
                <div class="total-label">设备总数</div>
              </div>
            </div>
            <div class="chart-legend">
              <div
                v-for="(type, index) in overviewData?.deviceTypeStatistics ||
                []"
                :key="type.typeId"
                class="legend-item"
              >
                <div
                  class="legend-color"
                  :style="{
                    backgroundColor: colorList[index % colorList.length],
                  }"
                ></div>
                <span class="legend-label">{{ type.typeName }}</span>
                <span class="legend-value">{{ type.total_count }}</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 设备状态分布 -->
        <div class="chart-card">
          <div class="card-header">
            <h3>设备状态分布</h3>
          </div>
          <div class="chart-content">
            <div class="bar-chart-container">
              <div ref="barChartRef" class="bar-chart"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最新记录区域 -->
    <div class="records-section">
      <div class="records-row">
        <!-- 申请记录 -->
        <div class="record-card">
          <div class="card-header">
            <h3>设备申请</h3>
            <div class="header-stats">
              <span class="pending-count">申请总数: {{ applysCount }}</span>
            </div>
          </div>
          <div class="record-list">
            <div v-for="record in applys" :key="record.id" class="record-item">
              <div class="record-info">
                <div class="record-title">{{ record.deviceName }}</div>
                <div class="record-user">
                  申请人: {{ record.chargeUser?.name || "--" }}
                </div>
              </div>
              <div class="record-meta">
                <div class="record-time">
                  申请时间: {{ formatDate(record.applicationTime) || "--" }}
                </div>
                <div class="record-status" :class="record.applicationStatus">
                  {{
                    reservationStatusMap[
                      record.applicationStatus as keyof typeof reservationStatusMap
                    ] || record.applicationStatus
                  }}
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 预约记录 -->
        <div class="record-card">
          <div class="card-header">
            <h3>设备预约</h3>
            <div class="header-stats">
              <span class="pending-count"
                >预约总数: {{ reservationsCount }}</span
              >
            </div>
          </div>
          <div class="record-list">
            <div
              v-for="record in reservations"
              :key="record.id"
              class="record-item"
            >
              <div class="record-info">
                <div class="record-title">{{ record.deviceName }}</div>
                <div class="record-user">
                  预约人: {{ record.deviceChargeUserInfo?.name || "--" }}
                </div>
              </div>
              <div class="record-meta">
                <div class="record-time">
                  预约时间:
                  <span>{{
                    formatDate(record.reservationStartTime) || "--"
                  }}</span>
                  <span>{{
                    formatDate(record.reservationEndTime) || "--"
                  }}</span>
                </div>
                <div class="record-status" :class="record.reservationStatus">
                  {{
                    reservationStatusMap[
                      record.reservationStatus as keyof typeof reservationStatusMap
                    ] || record.reservationStatus
                  }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="records-row">
        <!-- 报修工单 -->
        <div class="record-card">
          <div class="card-header">
            <h3>报修工单</h3>
            <div class="header-stats">
              <span class="pending-count">报修工单总数: {{ repairCount }}</span>
            </div>
          </div>
          <div class="record-list">
            <div
              v-for="(record, index) in RepairTableData"
              :key="record.id || index"
              class="record-item"
            >
              <div class="record-info">
                <div class="record-title">{{ record.content }}</div>
                <div class="record-user">
                  处理人: {{ (record as any)?.maintainerInfo?.name || record?.maintainerCode || "--" }}
                </div>
              </div>
              <div class="record-meta">
                <div class="record-time">
                  处理时间:
                  <span>
                    {{
                      (record.startTime && formatDate(record.startTime)) || "--"
                    }}</span
                  >
                  至
                  <span>
                    {{
                      (record.endTime && formatDate(record.endTime)) || "--"
                    }}</span
                  >
                </div>
                <div class="record-status" :class="record.status">
                  {{
                    statusMap[record.status as keyof typeof statusMap] ||
                    record.status
                  }}
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 保养计划 -->
        <div class="record-card">
          <div class="card-header">
            <h3>保养计划</h3>
            <div class="header-stats">
              <span class="pending-count"
                >保养计划总数: {{ maintenancePlansCount }}</span
              >
            </div>
          </div>
          <div class="record-list">
            <div
              v-for="record in maintenancePlans"
              :key="record.id"
              class="record-item"
            >
              <div class="record-info">
                <div class="record-title">{{ record.planName }}</div>
                <div class="record-user">保养设备: {{ record.deviceName }}</div>
              </div>
              <div class="record-meta">
                <div class="record-time">
                  计划时间:
                  {{ formatDate(record.planDate) || "--" }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 更新时间 -->
    <div class="system-status">
      <div class="status-item">
        <span class="status-label">系统状态</span>
        <span class="status-value online">运行正常</span>
      </div>
      <div class="status-item">
        <span class="status-label">当前时间</span>
        <span class="status-value">{{ currentTime }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from "vue";
import { useRouter } from "vue-router";
import { User, Monitor, Calendar, SwitchButton } from "@element-plus/icons-vue";
import * as echarts from "echarts";
import { removeCookie } from "@/assets/js/cookie";
import { formatDate } from "@/assets/js/utils";
import { overviewAPI } from "@/api/service/statistics";
import { getRepairOrdersPageAPI } from "@/api/service/repairWorkOrder";
import { RepairWorkOrderType } from "@/api/types/repairWorkOrder";
import { getMaintenancePlansByPageAPI } from "@/api/service/maintenancePlan";
import { pageAPI } from "@/api/service/reservations";
import { searchAPI } from "@/api/service/deviceApplicant";

import { ElMessage } from "element-plus";

// 路由实例
const router = useRouter();

// 用户信息
const userInfo = JSON.parse(localStorage.getItem("userInfo") || "{}");
let userRole = "user";
userInfo.roles.forEach((item: any) => {
  if (item.id === 4) {
    userRole = "expert";
  }
  if (item.id === 1 || item.id === 2) {
    userRole = "admin";
  }
});

// 跳转到工作台
const goToWorkspace = () => {
  // 根据角色进行跳转
  let _routeName = "EquipmentBooking";
  if (userRole === "user") {
    _routeName = "EquipmentBooking";
  }
  if (userRole === "expert") {
    _routeName = "EquipmentBookingManage";
  }
  if (userRole === "admin") {
    _routeName = "Equipment";
  }
  router.push({
    name: _routeName,
  });
};
// 退出登录
const logout = () => {
  localStorage.removeItem("userInfo");
  removeCookie("token");
  router.push({
    name: "Login",
  });
};

// 当前时间
const currentTime = ref("");
// 更新时间函数
const updateTime = () => {
  const now = new Date();
  currentTime.value = now.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
};
// 定时器
let timeInterval: any;

// 获取统计信息
const overviewData = ref<any>(null);
const getOverviewAPI = () => {
  overviewAPI()
    .then((response) => {
      const data = response.data || response; // 处理可能的AxiosResponse包装
      overviewData.value = data;
      overviewData.value.deviceStatusStatistics = [
        {
          statusName: "空闲",
          totalCount: data.total_idle_count,
        },
        {
          statusName: "预约中",
          totalCount: data.total_reserved_count,
        },
        {
          statusName: "使用中",
          totalCount: data.total_in_use_count,
        },
        {
          statusName: "损坏",
          totalCount: data.total_damaged_count,
        },
        {
          statusName: "报废",
          totalCount: data.total_scrapped_count,
        },
      ];
    })
    .catch((error) => {
      ElMessage.error(error.message);
    });
};
getOverviewAPI();

// 图表实例引用
const pieChartRef = ref<HTMLDivElement>();
const barChartRef = ref<HTMLDivElement>();
let pieChartInstance: echarts.ECharts | null = null;
let barChartInstance: echarts.ECharts | null = null;

// 初始化图表
const initCharts = async () => {
  await nextTick();

  // 初始化饼图
  if (pieChartRef.value) {
    pieChartInstance = echarts.init(pieChartRef.value);
    pieChartInstance.setOption(pieChartOption.value);
  }

  // 初始化条形图
  if (barChartRef.value) {
    barChartInstance = echarts.init(barChartRef.value);
    barChartInstance.setOption(barChartOption.value);
  }

  // 监听窗口大小变化
  window.addEventListener("resize", handleResize);
};

// 处理窗口大小变化
const handleResize = () => {
  pieChartInstance?.resize();
  barChartInstance?.resize();
};

// 销毁图表
const destroyCharts = () => {
  pieChartInstance?.dispose();
  barChartInstance?.dispose();
  pieChartInstance = null;
  barChartInstance = null;
  window.removeEventListener("resize", handleResize);
};

const colorList = ref(["#00a3ff", "#36c361", "#ff9500", "#f56c6c"]);

// 监听数据变化，更新图表
watch(
  [overviewData],
  () => {
    if (pieChartInstance) {
      pieChartInstance.setOption(pieChartOption.value);
    }
    if (barChartInstance) {
      barChartInstance.setOption(barChartOption.value);
    }
  },
  { deep: true }
);

// 饼图配置
const pieChartOption = computed(() => ({
  tooltip: {
    trigger: "item",
    formatter: "{a} <br/>{b}: {c} ({d}%)",
    backgroundColor: "rgba(0, 0, 0, 0.8)",
    borderColor: "transparent",
    textStyle: {
      color: "#fff",
      fontSize: 12,
    },
  },
  legend: {
    show: false,
  },
  series: [
    {
      name: "设备类型",
      type: "pie",
      radius: ["40%", "70%"],
      center: ["50%", "50%"],
      avoidLabelOverlap: false,
      label: {
        show: false,
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 14,
          fontWeight: "bold",
        },
        scaleSize: 1.1,
      },
      labelLine: {
        show: false,
      },
      data: (overviewData.value?.deviceTypeStatistics || []).map(
        (type: any, index: number) => ({
          value: type.total_count,
          name: type.typeName,
          itemStyle: {
            color: colorList.value[index % colorList.value.length],
          },
        })
      ),
    },
  ],
}));

// 条形图配置
const barChartOption = computed(() => ({
  tooltip: {
    trigger: "axis",
    axisPointer: {
      type: "none",
    },
    backgroundColor: "rgba(0, 0, 0, 0.8)",
    borderColor: "transparent",
    textStyle: {
      color: "#fff",
      fontSize: 12,
    },
    formatter: (params: any) => {
      const data = params[0];
      return `${data.name}: ${data.value}台`;
    },
  },
  grid: {
    left: "10%",
    right: "10%",
    top: "10%",
    bottom: "10%",
    containLabel: true,
  },
  xAxis: {
    type: "value",
    show: false,
    max:
      Math.max(
        ...(overviewData.value?.deviceStatusStatistics || []).map(
          (s: any) => s.totalCount
        )
      ) * 1.2,
  },
  yAxis: {
    type: "category",
    data: (overviewData.value?.deviceStatusStatistics || []).map(
      (s: any) => s.statusName
    ),
    axisLine: {
      show: false,
    },
    axisTick: {
      show: false,
    },
    axisLabel: {
      color: "#666",
      fontSize: 14,
      margin: 8,
    },
  },
  series: [
    {
      type: "bar",
      data: (overviewData.value?.deviceStatusStatistics || []).map(
        (status: any, index: number) => ({
          value: status.totalCount,
          itemStyle: {
            color: colorList.value[index % colorList.value.length],
            borderRadius: [0, 4, 4, 0],
          },
        })
      ),
      barHeight: 24,
      label: {
        show: true,
        position: "right",
        color: "#333",
        fontSize: 12,
        fontWeight: "600",
        formatter: "{c}台",
      },
    },
  ],
}));

// 报修工单
const statusMap = {
  IN_PROGRESS: "进行中",
  COMPLETED: "已完成",
};
const RepairTableData = ref<RepairWorkOrderType[]>([]);
const repairCount = ref(0);
function getRepairWorkOrderList() {
  getRepairOrdersPageAPI({
    page: 1,
    size: 5,
    status: "",
    deviceId: "",
    maintainerCode: "",
    startTimeFrom: null,
    startTimeTo: null,
  })
    .then((_data: any) => {
      const data = _data.content as RepairWorkOrderType[];
      RepairTableData.value = data;
      repairCount.value = _data.totalElements;
    })
    .catch(() => {
      ElMessage.error("获取报修工单列表失败");
    });
}
getRepairWorkOrderList();

// 保养计划
const maintenancePlans = ref<any[]>([]);
const maintenancePlansCount = ref(0);
const getMaintenancePlanList = async () => {
  try {
    const response = await getMaintenancePlansByPageAPI({
      page: 1,
      size: 5,
    });
    const data = response as any;
    maintenancePlans.value = data.content as any;
    maintenancePlansCount.value = data.totalElements;
  } catch (error) {
    ElMessage.error("获取保养计划失败");
  }
};
getMaintenancePlanList();

// 预约记录
const reservationStatusMap = {
  APPROVING: "审批中",
  APPROVED: "已通过",
  REJECTED: "已拒绝",
  CANCELLED: "已取消",
  RETURNED: "已归还",
};
const reservations = ref<any[]>([]);
const reservationsCount = ref(0);
const getReservationsList = async () => {
  try {
    const response = await pageAPI({
      page: 1,
      size: 5,
    });
    const data = response as any;
    reservations.value = data.content;
    reservationsCount.value = data.totalElements;
  } catch (error) {
    ElMessage.error("获取预约记录失败");
  }
};
getReservationsList();

// 申请记录
const applys = ref<any[]>([]);
const applysCount = ref(0);
const getApplysList = async () => {
  try {
    const response = await searchAPI({
      page: 1,
      size: 5,
      userCode: "",
      applicationStatus: "",
      keyword: "",
      deviceTypeId: "",
      deviceStatus: "",
      location: "",
      belong: "",
    });
    const data = response as any;
    applys.value = data.content;
    applysCount.value = data.totalElements;
  } catch (error) {
    ElMessage.error("获取预约记录失败");
  }
};
getApplysList();

onMounted(() => {
  updateTime();
  timeInterval = setInterval(updateTime, 1000);
  initCharts();
});

onUnmounted(() => {
  if (timeInterval) {
    clearInterval(timeInterval);
  }
  destroyCharts();
});
</script>

<style scoped lang="scss">
#PortalPage {
  width: 100%;
  height: calc(100vh - 64px);
  background: #fff;
  padding: 0;
  box-sizing: border-box;
  overflow: auto;
}

// 用户信息头部区域
.user-header {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);

  .user-info {
    display: flex;
    align-items: center;
    gap: 8px;

    .user-avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    }

    .user-name {
      font-size: 14px;
      font-weight: 500;
      color: #333;
      margin-right: 8px;
    }
  }

  .workspace-entry {
    .el-button {
      border-radius: 18px;
      padding: 6px 16px;
      font-size: 14px;
      font-weight: 500;
      box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
      }

      .el-icon {
        margin-right: 4px;
      }
    }
  }
}

// 学校Banner样式
.school-banner {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-bottom: 32px;

  .banner-background {
    .banner-image {
      width: 100%;
      height: auto;
      display: block;
    }

    .banner-overlay {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(
        135deg,
        rgb(102, 126, 234, 0.8) 0%,
        rgb(118, 75, 162, 0.8) 100%
      );
    }

    .banner-pattern {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: radial-gradient(
          circle at 20% 20%,
          rgba(255, 255, 255, 0.1) 0%,
          transparent 50%
        ),
        radial-gradient(
          circle at 80% 80%,
          rgba(255, 255, 255, 0.1) 0%,
          transparent 50%
        ),
        radial-gradient(
          circle at 40% 40%,
          rgba(255, 255, 255, 0.05) 0%,
          transparent 50%
        );
    }
  }

  .banner-content {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    width: 100%;
    margin: 0 auto;
  }

  .banner-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    .school-info-container {
      position: absolute;
      top: 2rem;
      left: 20px;
      .school-logo {
        .logo-img {
          width: 80px;
          height: 80px;
          object-fit: contain;
          background: rgba(255, 255, 255, 0.1);
          border-radius: 16px;
          padding: 8px;
          backdrop-filter: blur(10px);
          border: 1px solid rgba(255, 255, 255, 0.2);
        }
      }

      .school-info {
        display: flex;
        align-items: center;
        .school-name {
          font-size: 3.2rem;
          font-weight: 700;
          color: white;
          text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
          letter-spacing: 1px;
          margin-right: 1rem;
        }

        .school-desc {
          font-size: 3rem;
          color: rgba(255, 255, 255, 0.9);
          margin: 0;
          font-weight: 400;
          text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
        }
      }
    }

    .banner-decoration {
      position: absolute;
      top: 8rem;
      left: 32rem;
      width: 120px;
      height: 120px;
      pointer-events: none;
      z-index: 999;

      .decoration-circle {
        position: absolute;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);

        &.circle-1 {
          width: 80px;
          height: 80px;
          top: 0;
          right: 0;
          animation: float 6s ease-in-out infinite;
        }

        &.circle-2 {
          width: 60px;
          height: 60px;
          top: 30px;
          right: 50px;
          animation: float 6s ease-in-out infinite 2s;
        }

        &.circle-3 {
          width: 40px;
          height: 40px;
          top: 60px;
          right: 20px;
          animation: float 6s ease-in-out infinite 4s;
        }
      }
    }

    .message-panel {
      position: absolute;
      top: 10rem;
      left: 2rem;
      background: rgba(255, 255, 255, 0.15);
      backdrop-filter: blur(20px);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 16px;
      padding: 20px;
      width: 40rem;
      max-width: 380px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
      transition: all 0.3s ease;

      &:hover {
        background: rgba(255, 255, 255, 0.2);
        border-color: rgba(255, 255, 255, 0.3);
        transform: translateY(-2px);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
      }

      .panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 16px;

        .panel-title {
          display: flex;
          align-items: center;
          gap: 8px;
          font-size: 16px;
          font-weight: 600;
          color: white;

          .title-icon {
            color: #fbbf24;
            animation: bellRing 2s ease-in-out infinite;
          }
        }

        .panel-badge {
          background: linear-gradient(135deg, #ef4444, #f97316);
          color: white;
          border-radius: 12px;
          padding: 4px 10px;
          font-size: 12px;
          font-weight: 600;
          min-width: 24px;
          text-align: center;
          box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
        }
      }

      .panel-content {
        .no-messages {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          padding: 32px 16px;
          color: rgba(255, 255, 255, 0.7);

          .no-message-icon {
            font-size: 32px;
            margin-bottom: 8px;
            opacity: 0.6;
          }

          span {
            font-size: 14px;
          }
        }

        .message-list {
          .message-item {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            padding: 14px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            cursor: pointer;
            transition: all 0.3s ease;
            border-radius: 8px;
            margin: 0 -8px;
            padding-left: 8px;
            padding-right: 8px;

            &:hover {
              background: rgba(255, 255, 255, 0.1);
              transform: translateX(4px);
            }

            &:last-child {
              border-bottom: none;
            }

            &.unread {
              background: rgba(255, 255, 255, 0.05);

              .message-text {
                font-weight: 600;
              }
            }

            .message-type-indicator {
              width: 4px;
              height: 40px;
              border-radius: 2px;
              margin-top: 2px;
              flex-shrink: 0;

              &.type-danger {
                background: linear-gradient(135deg, #ef4444, #dc2626);
                box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
              }

              &.type-warning {
                background: linear-gradient(135deg, #f59e0b, #d97706);
                box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
              }

              &.type-info {
                background: linear-gradient(135deg, #3b82f6, #2563eb);
                box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
              }

              &.type-default {
                background: linear-gradient(135deg, #6b7280, #4b5563);
                box-shadow: 0 0 8px rgba(107, 114, 128, 0.4);
              }
            }

            .message-content {
              flex: 1;
              min-width: 0;

              .message-text {
                color: white;
                font-size: 14px;
                line-height: 1.4;
                margin-bottom: 6px;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                overflow: hidden;
                text-overflow: ellipsis;
              }

              .message-meta {
                display: flex;
                justify-content: space-between;
                align-items: center;
                gap: 12px;

                .message-type {
                  font-size: 12px;
                  color: rgba(255, 255, 255, 0.8);
                  background: rgba(255, 255, 255, 0.1);
                  padding: 2px 8px;
                  border-radius: 10px;
                  flex-shrink: 0;
                }

                .message-time {
                  font-size: 11px;
                  color: rgba(255, 255, 255, 0.6);
                  white-space: nowrap;
                }
              }
            }
          }
        }

        .panel-footer {
          margin-top: 16px;
          padding-top: 16px;
          border-top: 1px solid rgba(255, 255, 255, 0.1);
          text-align: center;

          .view-more-btn {
            color: white;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.3s ease;

            &:hover {
              color: #fbbf24;
              transform: translateX(4px);
            }

            .el-icon {
              margin-left: 4px;
              transition: transform 0.3s ease;
            }

            &:hover .el-icon {
              transform: translateX(2px);
            }
          }
        }
      }
    }
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.2);
  }
}

@keyframes bellRing {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: rotate(0deg);
  }
  10% {
    transform: rotate(10deg);
  }
  30% {
    transform: rotate(-10deg);
  }
  60% {
    transform: rotate(5deg);
  }
  70% {
    transform: rotate(-5deg);
  }
}

.portal-header {
  text-align: center;
  margin-bottom: 32px;
  padding: 0 24px;

  .page-title {
    font-size: 32px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0 0 8px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .page-subtitle {
    font-size: 16px;
    color: #666;
    margin: 0;
  }
}

.stats-grid {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
  padding: 0 24px;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
  }

  .stat-icon {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 20px;
    color: white;
  }

  .stat-content {
    flex: 1;

    h3 {
      font-size: 14px;
      color: #666;
      margin: 0 0 8px 0;
      font-weight: 500;
    }

    .stat-number {
      font-size: 32px;
      font-weight: 700;
      color: #1a1a1a;
      line-height: 1;
      margin-bottom: 4px;
    }

    .stat-desc {
      font-size: 12px;
      color: #999;
      margin: 0;
    }
  }

  &.user-stats .stat-icon {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  }

  &.service-stats .stat-icon {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  }

  &.equipment-stats .stat-icon {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  }

  &.booking-stats .stat-icon {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  }
}

.charts-section {
  margin-bottom: 32px;
  padding: 0 24px;
}

.chart-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.chart-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);

  .card-header {
    padding-bottom: 5px;
    // background-color: $bg-color-page;
    border-bottom: 1px solid $border-color-primary;
    margin-bottom: 24px;

    h3 {
      font-size: 18px;
      font-weight: 600;
      color: #1a1a1a;
      margin: 0;
    }
  }

  .chart-content {
    display: flex;
    align-items: center;
    gap: 32px;
  }
}

.pie-chart-container {
  position: relative;
  width: 250px;
  height: 250px;

  .pie-chart {
    width: 100%;
    height: 100%;
  }

  .pie-chart-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    z-index: 10;

    .total-count {
      font-size: 28px;
      font-weight: 700;
      color: #1a1a1a;
      line-height: 1;
    }

    .total-label {
      font-size: 12px;
      color: #666;
      margin-top: 4px;
    }
  }
}

.chart-legend {
  flex: 1;

  .legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 16px;

    .legend-color {
      width: 12px;
      height: 12px;
      border-radius: 2px;
      margin-right: 12px;
    }

    .legend-label {
      font-size: 14px;
      color: #666;
    }

    .legend-value {
      font-size: 16px;
      font-weight: 600;
      color: #1a1a1a;
    }
  }
}

.bar-chart-container {
  width: 100%;
  height: 280px;

  .bar-chart {
    width: 100%;
    height: 100%;
  }
}

.records-section {
  padding: 0 24px;

  .records-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
  }
}

.record-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 5px;
    // background-color: $bg-color-page;
    border-bottom: 1px solid $border-color-primary;

    h3 {
      font-size: 18px;
      font-weight: 600;
      color: #1a1a1a;
      margin: 0;
    }

    .header-stats {
      .pending-count {
        font-size: 12px;
        color: #00a3ff;
        background: #e8f4ff;
        padding: 4px 8px;
        border-radius: 12px;
        font-weight: 500;
      }
    }
  }
}

.record-list {
  .record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.3s ease;

    &:hover {
      background: rgba(102, 126, 234, 0.05);
      padding-left: 8px;
      padding-right: 8px;
      margin-left: -8px;
      margin-right: -8px;
      border-radius: 8px;
    }

    &:last-child {
      border-bottom: none;
    }

    .record-info {
      flex: 1;

      .record-title {
        font-size: 14px;
        color: #1a1a1a;
        font-weight: 500;
        margin-bottom: 4px;
      }

      .record-user {
        font-size: 12px;
        color: #666;
      }
    }

    .record-meta {
      text-align: right;

      .record-time {
        font-size: 12px;
        color: #999;
        margin-bottom: 4px;
      }

      .record-status {
        font-size: 12px;
        padding: 2px 8px;
        border-radius: 12px;
        font-weight: 500;

        &.status-pending {
          color: #ff9500;
          background: #fff3e0;
        }

        &.status-approved {
          color: #36c361;
          background: #e8f5e8;
        }

        &.status-rejected {
          color: #f56c6c;
          background: #ffeaea;
        }

        &.status-confirmed {
          color: #00a3ff;
          background: #e8f4ff;
        }

        &.status-inuse {
          color: #9c27b0;
          background: #f3e5f5;
        }

        &.status-booked {
          color: #ff9500;
          background: #fff3e0;
        }

        &.status-processing {
          color: #2196f3;
          background: #e3f2fd;
        }

        &.status-completed {
          color: #4caf50;
          background: #e8f5e9;
        }

        &.status-planned {
          color: #607d8b;
          background: #eceff1;
        }
      }
    }
  }
}

.system-status {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  background: #fff;
  border-top: 1px solid $border-color-primary;
  padding: 16px 20px;
  z-index: 999;

  .status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;

    &:last-child {
      margin-left: 10rem;
    }

    .status-label {
      font-size: 14px;
      color: $text-color-secondary;
      margin-right: 20px;
    }

    .status-value {
      font-size: 14px;
      font-weight: 600;
      color: $text-color-secondary;

      &.online {
        color: $color-success;
        position: relative;

        &::before {
          content: "";
          width: 8px;
          height: 8px;
          background: $color-success;
          border-radius: 50%;
          display: inline-block;
          margin-right: 6px;
          animation: pulse 2s ease-in-out infinite;
        }
      }
    }
  }
}
.APPROVING {
  color: $color-success;
}
.APPROVED {
  color: $color-brand;
}
.REJECTED {
  color: $color-danger;
}
.CANCELLED {
  color: $color-danger;
}
.RETURNED {
  color: $text-color-regular;
}
.IN_PROGRESS {
  color: $color-success;
}
.COMPLETED {
  color: $color-success;
}
.NOT_STARTED {
  color: $text-color-regular;
}
</style>
